bitkeeper revision 1.1159.45.15 (4126390c2dSRHYLR3YNd9JysCy4XTw)
authoriap10@tetris.cl.cam.ac.uk <iap10@tetris.cl.cam.ac.uk>
Fri, 20 Aug 2004 17:46:52 +0000 (17:46 +0000)
committeriap10@tetris.cl.cam.ac.uk <iap10@tetris.cl.cam.ac.uk>
Fri, 20 Aug 2004 17:46:52 +0000 (17:46 +0000)
Export new mapping interface 'xc_map_foreign'

tools/libxc/xc.h
tools/libxc/xc_linux_restore.c
tools/libxc/xc_linux_save.c
tools/libxc/xc_private.c
tools/libxc/xc_private.h
tools/python/xen/lowlevel/xu/xu.c

index 8b54ed020776d19fee521451a755f5364f3cf6c6..0da159d8703c304e5654201825dbde86984276ae 100644 (file)
@@ -231,4 +231,11 @@ int xc_domain_setmaxmem(int xc_handle,
                             unsigned int max_memkb);
 
 
+void *xc_map_foreign_range(int xc_handle, u32 dom,
+                            int size, int prot,
+                            unsigned long mfn );
+
+void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
+                           unsigned long *arr, int num );
+
 #endif /* __XC_H__ */
index 6d4f0906aa1b545cb440331289f4a64262e688a5..3c984b4f191a3b1a9c8c522a03b8a9c86184eb7c 100644 (file)
@@ -325,7 +325,7 @@ int xc_linux_restore(int xc_handle, XcIOContext *ioctxt)
             }          
         }
  
-        if ( (region_base = mfn_mapper_map_batch( xc_handle, dom, 
+        if ( (region_base = xc_map_foreign_batch( xc_handle, dom, 
                                                   PROT_WRITE,
                                                   region_mfn,
                                                   j )) == 0 )
@@ -631,7 +631,7 @@ printf("XXXXXXXXXXXXXXX pin L2\n");
     }
     
     if ( (live_pfn_to_mfn_table = 
-          mfn_mapper_map_batch(xc_handle, dom, 
+         xc_map_foreign_batch(xc_handle, dom, 
                                PROT_WRITE,
                                pfn_to_mfn_frame_list,
                                (nr_pfns+1023)/1024 )) == 0 )
index cfcc6cd0c8de26d9b40cf658d0c276b52665913a..57b4f1ab5603019c2d4c26710c2dec6bd8532393 100644 (file)
 /*
  * Returns TRUE if the given machine frame number has a unique mapping
  * in the guest's pseudophysical map.
- * 0x80000000-3 mark the shared_info, and blk/net rings
  */
 
-#if 0 
-#define MFN_IS_IN_PSEUDOPHYS_MAP(_mfn)                                    \
-    (((_mfn) < (1024*1024)) &&                                            \
-     (((live_mfn_to_pfn_table[_mfn] < nr_pfns) &&                         \
-       (live_pfn_to_mfn_table[live_mfn_to_pfn_table[_mfn]] == (_mfn))) || \
-      ((live_mfn_to_pfn_table[_mfn] >= 0x80000000) &&                     \
-       (live_mfn_to_pfn_table[_mfn] <= 0x80000003)) ||                    \
-      (live_pfn_to_mfn_table[live_mfn_to_pfn_table[_mfn]] == 0x80000004)))
-#endif
 #define MFN_IS_IN_PSEUDOPHYS_MAP(_mfn)                                    \
     (((_mfn) < (1024*1024)) &&                                            \
      ((live_mfn_to_pfn_table[_mfn] < nr_pfns) &&                         \
@@ -60,6 +50,8 @@
     _res;                                      \
 })
 
+#define is_mapped(pfn) (!((pfn) & 0x80000000UL))
+
 static inline int test_bit ( int nr, volatile void * addr)
 {
     return (((unsigned long*)addr)[nr/(sizeof(unsigned long)*8)] >> 
@@ -384,7 +376,7 @@ int xc_linux_save(int xc_handle, XcIOContext *ioctxt)
 
 
     /* Map the shared info frame */
-    live_shinfo = mfn_mapper_map_single(xc_handle, domid,
+    live_shinfo = xc_map_foreign_range(xc_handle, domid,
                                         PAGE_SIZE, PROT_READ,
                                         shared_info_frame);
 
@@ -395,7 +387,7 @@ int xc_linux_save(int xc_handle, XcIOContext *ioctxt)
 
     /* the pfn_to_mfn_frame_list fits in a single page */
     live_pfn_to_mfn_frame_list = 
-        mfn_mapper_map_single(xc_handle, domid, 
+        xc_map_foreign_range(xc_handle, domid, 
                               PAGE_SIZE, PROT_READ, 
                               live_shinfo->arch.pfn_to_mfn_frame_list );
 
@@ -410,7 +402,7 @@ int xc_linux_save(int xc_handle, XcIOContext *ioctxt)
        (its not clear why it would want to change them, and we'll be OK
        from a safety POV anyhow. */
 
-    live_pfn_to_mfn_table = mfn_mapper_map_batch(xc_handle, domid, 
+    live_pfn_to_mfn_table = xc_map_foreign_batch(xc_handle, domid, 
                                                  PROT_READ,
                                                  live_pfn_to_mfn_frame_list,
                                                  (nr_pfns+1023)/1024 );  
@@ -421,12 +413,12 @@ int xc_linux_save(int xc_handle, XcIOContext *ioctxt)
 
     /* Setup the mfn_to_pfn table mapping */
     mfn_to_pfn_table_start_mfn = xc_get_m2p_start_mfn( xc_handle );
-
+printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n");
     live_mfn_to_pfn_table = 
-       mfn_mapper_map_single(xc_handle, DOMID_XEN, 
+       xc_map_foreign_range(xc_handle, DOMID_XEN, 
                              PAGE_SIZE*1024, PROT_READ, 
                              mfn_to_pfn_table_start_mfn );
-
+printf("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n");
     /* Canonicalise the pfn-to-mfn table frame-number list. */
     memcpy( pfn_to_mfn_frame_list, live_pfn_to_mfn_frame_list, PAGE_SIZE );
 
@@ -530,7 +522,7 @@ printf("GO LIVE!!\n");
        {
            mfn = live_pfn_to_mfn_table[i];
            
-           if( (live_mfn_to_pfn_table[mfn] != i) && (mfn != 0x80000001) )
+           if( (live_mfn_to_pfn_table[mfn] != i) && (mfn != 0xffffffffUL) )
            {
                printf("i=0x%x mfn=%lx live_mfn_to_pfn_table=%lx\n",
                       i,mfn,live_mfn_to_pfn_table[mfn]);
@@ -629,7 +621,8 @@ printf("GO LIVE!!\n");
                 pfn_batch[batch] = n;
                 pfn_type[batch] = live_pfn_to_mfn_table[n];
 
-                if( pfn_type[batch] == 0x80000001 ){
+                if( ! is_mapped(pfn_type[batch]) )
+               {
                     /* not currently in pusedo-physical map -- set bit
                        in to_fix that we must send this page in last_iter
                        unless its sent sooner anyhow */
@@ -660,7 +653,7 @@ printf("GO LIVE!!\n");
             if ( batch == 0 )
                 goto skip; /* vanishingly unlikely... */
       
-            if ( (region_base = mfn_mapper_map_batch(xc_handle, domid, 
+            if ( (region_base = xc_map_foreign_batch(xc_handle, domid, 
                                                      PROT_READ,
                                                      pfn_type,
                                                      batch)) == 0 ){
@@ -870,7 +863,7 @@ printf("type fail: page %i mfn %08lx\n",j,pfn_type[j]);
 
        for ( i = 0, j = 0; i < nr_pfns; i++ )
        {
-           if ( live_pfn_to_mfn_table[i] >= 0x80000000UL )
+           if ( ! is_mapped(live_pfn_to_mfn_table[i]) )
                j++;
        }
 
@@ -882,7 +875,7 @@ printf("type fail: page %i mfn %08lx\n",j,pfn_type[j]);
 
        for ( i = 0, j = 0; i < nr_pfns; )
        {
-           if ( live_pfn_to_mfn_table[i] >= 0x80000000UL )
+           if ( ! is_mapped(live_pfn_to_mfn_table[i]) )
            {
                pfntab[j++] = i;
            }
@@ -901,7 +894,7 @@ printf("type fail: page %i mfn %08lx\n",j,pfn_type[j]);
 
     /* Map the suspend-record MFN to pin it. The page must be owned by 
        domid for this to succeed. */
-    p_srec = mfn_mapper_map_single(xc_handle, domid,
+    p_srec = xc_map_foreign_range(xc_handle, domid,
                                    sizeof(*p_srec), PROT_READ, 
                                    ctxt.cpu_ctxt.esi);
     if (!p_srec){
index 47d2fa5230a56b3954a2790f88a36fbd15d6cf53..795ac6e83bc045359c455bb2ab966d24faef4069 100644 (file)
@@ -133,7 +133,7 @@ void unmap_pfn(void *pm_handle, void *vaddr)
 
 /*******************/
 
-void *mfn_mapper_map_batch(int xc_handle, domid_t dom, int prot,
+void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
                            unsigned long *arr, int num )
 {
     privcmd_mmapbatch_t ioctlx; 
@@ -158,7 +158,7 @@ void *mfn_mapper_map_batch(int xc_handle, domid_t dom, int prot,
 
 /*******************/
 
-void *mfn_mapper_map_single(int xc_handle, domid_t dom,
+void *xc_map_foreign_range(int xc_handle, u32 dom,
                             int size, int prot,
                             unsigned long mfn )
 {
index d70f7df58a1dd8ab60d1b362e26c7b340044d8fb..9da98a25ab10e0a4a6f57ccefd3fac47a419a1f0 100644 (file)
@@ -220,23 +220,6 @@ typedef struct mfn_mapper {
     
 } mfn_mapper_t;
 
-void * mfn_mapper_map_single(int xc_handle, domid_t dom, int size, int prot, 
-                            unsigned long mfn );
-
-void * mfn_mapper_map_batch(int xc_handle, domid_t dom, int prot,
-                           unsigned long *arr, int num );
-
-mfn_mapper_t * mfn_mapper_init(int xc_handle, domid_t dom, int size, int prot);
-
-void * mfn_mapper_base(mfn_mapper_t *t);
-
-void mfn_mapper_close(mfn_mapper_t *t);
-
-int mfn_mapper_flush_queue(mfn_mapper_t *t);
-
-void * mfn_mapper_queue_entry(mfn_mapper_t *t, int offset, 
-                             unsigned long mfn, int size );
-
 long long  xc_domain_get_cpu_usage( int xc_handle, domid_t domid );
 
 #include "xc_io.h"
index 3b078e7d33c020b3640d20647a1f7d7c12882ca1..344cb8cc4b7022ee414ec3f6a8afd1e323383da5 100644 (file)
@@ -679,11 +679,12 @@ static PyTypeObject xu_message_type = {
  * *********************** PORT ***********************
  */
 
-static control_if_t *map_control_interface(int fd, unsigned long pfn)
+static control_if_t *map_control_interface(int fd, unsigned long pfn,
+                                          u32 dom)
 {
-    char *vaddr = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE,
-                       MAP_SHARED, fd, pfn * PAGE_SIZE);
-    if ( vaddr == MAP_FAILED )
+    char *vaddr = xc_map_foreign_range( fd, dom, PAGE_SIZE,
+                                       PROT_READ|PROT_WRITE, pfn );
+    if ( vaddr == NULL )
         return NULL;
     return (control_if_t *)(vaddr + 2048);
 }
@@ -695,8 +696,8 @@ static void unmap_control_interface(int fd, control_if_t *c)
 
 typedef struct xu_port_object {
     PyObject_HEAD;
-    int mem_fd;
     int xc_handle;
+    int connected;
     u32 remote_dom;
     int local_port, remote_port;
     control_if_t    *interface;
@@ -908,35 +909,25 @@ static int __xu_port_connect(xu_port_object *xup)
 {
     xc_dominfo_t info;
 
-    if ( xup->mem_fd != -1 )
-        return 0;
-
-    if ( (xup->mem_fd = open("/dev/mem", O_RDWR)) == -1 )
+    if ( xup->connected )
     {
-        PyErr_SetString(port_error, "Could not open '/dev/mem'");
-        return -1;
+       return 0;
     }
-    set_cloexec(xup->mem_fd);
-
-    /* Set the General-Purpose Subject whose page frame will be mapped. */
-    (void)ioctl(xup->mem_fd, _IO('M', 1), (unsigned long)xup->remote_dom);
 
     if ( (xc_domain_getinfo(xup->xc_handle, xup->remote_dom, 1, &info) != 1) ||
          (info.domid != xup->remote_dom) )
     {
         PyErr_SetString(port_error, "Failed to obtain domain status");
-        (void)close(xup->mem_fd);
-        xup->mem_fd = -1;
         return -1;
     }
 
     xup->interface = 
-        map_control_interface(xup->mem_fd, info.shared_info_frame);
+        map_control_interface(xup->xc_handle, info.shared_info_frame,
+                             xup->remote_dom);
+
     if ( xup->interface == NULL )
     {
         PyErr_SetString(port_error, "Failed to map domain control interface");
-        (void)close(xup->mem_fd);
-        xup->mem_fd = -1;
         return -1;
     }
 
@@ -946,16 +937,16 @@ static int __xu_port_connect(xu_port_object *xup)
     xup->rx_req_prod  = xup->interface->rx_req_prod;
     xup->rx_resp_cons = xup->interface->rx_resp_prod;
 
+    xup->connected = 1;
+
     return 0;
 }
 
 static void __xu_port_disconnect(xu_port_object *xup)
 {
-    if ( xup->mem_fd == -1 )
-        return;
-    unmap_control_interface(xup->mem_fd, xup->interface);
-    (void)close(xup->mem_fd);
-    xup->mem_fd = -1;
+    if ( xup->connected )
+       unmap_control_interface(xup->xc_handle, xup->interface);
+    xup->connected = 0;
 }
 
 static PyObject *xu_port_connect(PyObject *self, PyObject *args)
@@ -1057,8 +1048,8 @@ static PyObject *xu_port_new(PyObject *self, PyObject *args)
 
     xup = PyObject_New(xu_port_object, &xu_port_type);
 
+    xup->connected  = 0;
     xup->remote_dom = dom;
-    xup->mem_fd     = -1; /* currently disconnected */
 
     if ( (xup->xc_handle = xc_interface_open()) == -1 )
     {